<?php include_once('header.php'); ?>

<?php include_once('left_navigation.php'); ?>

<style type="text/css">

    .datepicker{

        z-index: 99999999999;

    }

</style>

<?php
include('../classess/class_manage_user.php');

$manage_user = new manageUser();
//print_r($_GET);exit;
//$affiliate_id = $_SESSION['id'];

if (isset($_GET['user_id'])) {
    $affiliate_id = $_GET['user_id'];
    $manageUser = '';
    if (isset($_POST['bank_name']) && $_POST['bank_name'] != '') {

        $manageUser = $manage_user->bankdetail_add($affiliate_id);
    }
    $banks_details = $manage_user->get_details($affiliate_id);
}
?>

<div class="col-lg-12"><!-- Start Middle Content Div-->

    <div class="box">

        <div class="row">		

            <div class="col-lg-12">

                <div class="box">

                    <div class="box-header" data-original-title>

                        <h2><i class="fa fa-user"></i><span class="break"></span>Users</h2>

                        <div class="box-icon">

                            <a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                            <a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>

                        </div>

                    </div>

                    <div class="box-content">

<?php
if (isset($delete_activate_user)) {
    ?>

                            <div class="alert alert-info">

                                <div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>

                                <div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $delete_activate_user; ?></div>

                                <div style="clear:both;"></div>							

                            </div>

    <?php
}
?>

                        <div class="search_box">

                            <!--<div class="fl_left sel_label_search">Search:</div>

                            <div class="fl_left" style="width:60%;">									

                                    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?mng_wdr=1" id="search_form" name="search_form">

                                            <input type="text" name="search_value" id="search_value" placeholder="Search" value="<?php if (isset($_POST['search_value'])) {
    echo $_POST['search_value'];
} else {
    echo '';
} if (isset($_GET['srch_value'])) {
    echo $_GET['srch_value'];
} else {
    echo '';
} ?>">&nbsp;

                                            <input type="submit" name="submit_search" id="submit_search" class="btn btn-blue srch_btn" value="Search">

                                    </form>



                            </div>

                            <div class="clear_fix"></div>-->

                            <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?mng_wdr=1" id="search_form" name="search_form">

                                <div class="fl_left" style="width:50%;">

                                    <div class="fl_left sel_label_search" style="width:11%;">Search:</div>

                                    <div class="fl_left" style="width:86%;">	

                                        <input type="text" name="search_value" id="search_value" placeholder="Search" value="<?php if (isset($_POST['search_value'])) {
    echo $_POST['search_value'];
} else {
    echo '';
} if (isset($_GET['srch_value'])) {
    echo $_GET['srch_value'];
} else {
    echo '';
} ?>" style="width:45%;">&nbsp;

                                        <input type="submit" name="submit_search" id="submit_search" class="btn btn-blue srch_btn" value="Search">										

                                    </div>

                                    <div class="clear_fix"></div>

                                </div>

                                <div class="fl_right">

                                    <div class="fl_left" style="width:15%; margin-top:5px;">Number Of Records : </div>

                                    <div class="fl_left">

                                        <?php
                                        $limit_10 = '';

                                        $limit_25 = '';

                                        $limit_50 = '';

                                        $limit_100 = '';

                                        if (isset($_POST['sel_limit'])) {

/*                                            if ($_POST['sel_limit'] == '10') {

                                                $limit_10 = "selected='selected'";
                                            }
*/
                                            if ($_POST['sel_limit'] == '25') {

                                                $limit_25 = "selected='selected'";
                                            }

                                            if ($_POST['sel_limit'] == '50') {

                                                $limit_50 = "selected='selected'";
                                            }

                                            if ($_POST['sel_limit'] == '100') {

                                                $limit_100 = "selected='selected'";
                                            }
                                        }

                                        if (isset($_GET['sel_get_limit'])) {

                                           /* if ($_GET['sel_get_limit'] == '10') {

                                                $limit_10 = "selected='selected'";
                                            }*/

                                            if ($_GET['sel_get_limit'] == '25') {

                                                $limit_25 = "selected='selected'";
                                            }

                                            if ($_GET['sel_get_limit'] == '50') {

                                                $limit_50 = "selected='selected'";
                                            }

                                            if ($_GET['sel_get_limit'] == '100') {

                                                $limit_100 = "selected='selected'";
                                            }
                                        }
                                        ?>

                                        <select name="sel_limit" id="sel_limit" onchange="javascript:document.search_form.submit();">

                                       <!--     <option value="10" <?php echo $limit_10; ?> >10</option>
-->
                                            <option value="25" <?php echo $limit_25; ?> >25</option>

                                            <option value="50" <?php echo $limit_50; ?> >50</option>

                                            <option value="100" <?php echo $limit_100; ?> >100</option>

                                        </select>



                                    </div>

                                    <div class="clear_fix"></div>

                                </div>

                                <div class="clear_fix"></div>							

                            </form>

                        </div>

                        <table class="table table-striped table-bordered">

                            <thead>

                                <tr>

                                    <th>S.No.</th>

                                    <th>User Name</th>
                                    <th>User Email</th>
                                    <th>Course Name</th>
                                    <th>Course Price</th>
                                    <th>Commission Percentage</th>
                                    <th>commission</th>
                                    <th>Month Year</th>

                                </tr>

                            </thead>   

                            <tbody>

<?php
$rec_limit = 25;

if (isset($_POST['sel_limit'])) {

    $rec_limit = $_POST['sel_limit'];
}



if (isset($_GET['sel_get_limit'])) {

    $rec_limit = $_GET['sel_get_limit'];
}



$condition_search = '';

$value = '';

if (isset($_POST['search_value'])) {

    $value = trim($_POST['search_value']);



    if (!empty($value)) {

        $cond_where = ' AND';

        $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
    }
}



if (isset($_GET['srch_value'])) {

    $value = $_GET['srch_value'];



    if (!empty($value)) {

        $cond_where = ' AND';



        $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
    }
}



//$select_count_course = "SELECT count(id) FROM tbl_commission WHERE user_admin_id= 'a_".$_GET['user_id']."'".$condition_search;
$select_count_course = "SELECT count(com.id) FROM tbl_commission as com  
    JOIN tbl_user as user  ON com.trainee_id = user.id          
                                JOIN tbl_courses as cour  ON com.course_id = cour.id
                                WHERE user_admin_id= 'a_" . $_GET['user_id'] . "'
                                    " . $condition_search;

$result_count_course = mysql_query($select_count_course);



$row = mysql_fetch_array($result_count_course);

$rec_count = $row[0];



if (isset($_GET['page'])) {

    $page = $_GET['page'] + 1;

    $offset = $rec_limit * $page;
} else {

    $page = 0;

    $offset = 0;
}



$serial_number = $page * $rec_limit;



$left_rec = $rec_count - ($page * $rec_limit);



//$select_trainer = "SELECT * FROM tbl_commission WHERE user_admin_id= 'a_".$_GET['user_id']."'".$condition_search." ORDER BY id DESC LIMIT ".$offset.", ".$rec_limit;
$select_trainer = "SELECT * FROM tbl_commission as com  
JOIN tbl_user as user  ON com.trainee_id = user.id                    
JOIN tbl_courses as cour  ON com.course_id = cour.id    
                WHERE user_admin_id= 'a_" . $_GET['user_id'] . "'
                " . $condition_search . " ORDER BY com.id DESC LIMIT " . $offset . ", " . $rec_limit;

$query_trainer = mysql_query($select_trainer) or die(mysql_error());



$i = 1;

if (mysql_num_rows($query_trainer) > 0) {
    $total_amount = '';
    while ($row = mysql_fetch_array($query_trainer)) {

        $serial_number++;
        $total_amount += $row['commission'];
        echo '<tr>
                    <td>' . $serial_number . '</td>
                    <td>' . $row['username'] . '</td>
                    <td>' . $row['email'] . '</td>
                    <td>' . $row['course_name'] . '</td>
                    <td>' . $row['course_fee'] . '</td>
                    <td>' . $row['commission_percentage'] . '</td>
                    <td>' . $row['commission'] . '</td>
                    <td>';
        $dateValue = $row['create_ts'];
        $dateValue = explode(" ", $dateValue);

        $time = strtotime($dateValue[0]);

        $month = date("F", $time);

        $year = date("Y", $time);

        $day = date("d", $time);

        echo $day . ' ' . $month . ' ' . $year;

        echo '</td>

											</tr>

										';

        $i++;
    }
} else {

    echo '<tr>

										<td colspan="9" style="text-align:center;">No Records Found</td>

									</tr>';
}
?>						

                            </tbody>

                        </table>  
                        <b>Total Amount:</b> $ <?php echo $total_amount; ?>

                        <!----------------
                        <div>
                                <div>
                                        <label> Bank Name:</label>
                                        <input type="text" id="bank_name" name="bank_name" value="">
                                </div>
                                <div>
                                <label>Account Number:</label>
                                        <input type="text" id="account_number" name="account_number" value="">
                                </div>
                                <div>
                                        <label>Withdraw:</label>
                                        <input type="text" id="withdraw" name="withdraw" value="">
                                </div>
                  
                        </div>
                ---------------->

<?php
echo '<ul class="pagination">';

if ($rec_count > $rec_limit) {

    if ($page > 0 && $left_rec > $rec_limit) {

        $last = $page - 2;

        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?mng_wdr=1&page=' . $last . '&srch_value=' . $value . '&sel_get_limit=' . $rec_limit . '" class="anc_click">Prev</a></li> ';

        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?mng_wdr=1&page=' . $page . '&srch_value=' . $value . '&sel_get_limit=' . $rec_limit . '" class="anc_click">Next</a></li>';
    } else if ($page == 0) {

        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?mng_wdr=1&page=' . $page . '&srch_value=' . $value . '&sel_get_limit=' . $rec_limit . '" class="anc_click">Next</a></li>';
    } else if ($left_rec < $rec_limit || $left_rec == $rec_limit) {

        $last = $page - 2;

        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?mng_wdr=1&page=' . $last . '&srch_value=' . $value . '&sel_get_limit=' . $rec_limit . '" class="anc_click">Prev</a></li>';
    }
}

echo '</ul>';
?>

                    </div>

                </div>

            </div><!--/col-->



        </div><!--/row-->

        <div class="col-lg-12"><!-- Start Middle Content Div-->

            <div class="box">

                <div class="box-header" data-original-title=""><!-- Start Box Header Div-->

                    <h2><i class="fa fa-edit"></i><span class="break"></span>Add Detail</h2>

                    <div class="box-icon">

                        <a href="gallery.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                        <a href="gallery.html#" class="btn-close"><i class="fa fa-times"></i></a>

                    </div>

                </div><!-- End Box Header Div-->


                <div class="box-content"><!-- Start Box Content Div-->

                    <div class="row">

                        <div class="col-sm-12">

                        <?php if ($manageUser) { ?>
                                <div class="alert alert-info">

                                    <div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>

                                    <div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $manageUser; ?></div>

                                    <div style="clear:both;"></div>							

                                </div>
<?php
}


$select_pending = "SELECT a.*,c.*, b.*, b.id as comm_id 
                    FROM tbl_user_details as a,tbl_user as c, tbl_commission as b 
                    WHERE  b.user_admin_id='a_" . $_GET['user_id'] . "' and c.reffered_by='a_" . $_GET['user_id'] . "' 
                    GROUP by c.id  ORDER BY c.id DESC LIMIT " . $offset . ", " . $rec_limit;

$query_pending = mysql_query($select_pending) or die(mysql_error());
$total_amount = '';
$pending_amount = '';
while ($row = mysql_fetch_array($query_pending)) {
    if ($row['is_active'] == 1 && $row['is_paid'] == 1) {
        $total_amount += $row['commission'];
    } else {
        $pending_amount += $row['commission'];
    }
}
?>
                            <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?mng_wdr=1&user_id=<?php echo $_GET['user_id'] ?>" name="add_aff_bank_detail" id="add_aff_bank_detail" enctype="multipart/form-data">

                                <div class="main_form_box col-sm-6">

                                    <div class="form-content  form-content-form">								

                                        <label>Bank Name</label>
                                        <input type="text" name="bank_name" id="bank_name" value="" > 

                                        <label>Account Number</label>
                                        <input type="text" name="account_number" id="account_number" value="" >

                                        <label>Transaction Id</label>
                                        <input type="text" name="transaction_id" id="transaction_id" value="" >

                                        <label>Date</label>
                                        <input readonly type="text" name="at_date" id="at_date" class="date-picker" value="">	
                                    </div>

                                </div>

                                <div class="main_form_box col-sm-6" >

                                    <div class="form-content  form-content-form">

                                        <label>Tds (%)</label>
                                        <input readonly type="text" name="tds" id="tds" value="10" >

                                        <label>Pending Amount</label>
                                        <input type="text" name="pending_amount" id="pending_amount" value="<?php echo $pending_amount; ?>" >

                                        <label>Total Amount</label>
                                        <input type="text" name="total_amount" id="total_amount" value=""> 

                                        <label>Note</label>
                                        <textarea  rows="5" cols="40" name="at_note" id="at_note" value=""></textarea>

                                        <label style="text-align:right; margin-top:35px;">

                                            <button type="button" class="btn btn-blue login_button" name="add_bank_detail" id="add_bank_detail">
                                                Add
                                            </button> 							

                                        </label>

                                    </div>

                                </div>


                                <div style="clear:both;"></div>

                            </form>

                        </div><!--/col-->

                    </div><!-- End Row div -->

                </div><!-- End Box Content Div -->

            </div><!-- End Box Div-->

        </div><!-- End Middle Content Div-->

        <div class="row">		

            <div class="col-lg-12">

                <div class="box">

                    <div class="box-header" data-original-title>

                        <h2><i class="fa fa-user"></i><span class="break"></span>Bank Detail</h2>

                        <div class="box-icon">

                            <a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                            <a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>

                        </div>

                    </div>

                    <div class="box-content">


                        <div class="search_box">

                            <!--                         <div class="fl_left sel_label_search">Search:</div>
                         
                                                     <div class="fl_left" style="width:60%;">									
                         
                                                         <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?aff_mn=1" id="search_form" name="search_form">
                         
                                                             <input type="text" name="search_value" id="search_value" placeholder="Search" value="<?php
                            if (isset($_POST['search_value'])) {
                                echo $_POST['search_value'];
                            } else {
                                echo '';
                            } if (isset($_GET['srch_value'])) {
                                echo $_GET['srch_value'];
                            } else {
                                echo '';
                            }
?>">&nbsp;
                         
                                                             <input type="submit" name="submit_search" id="submit_search" class="btn btn-blue srch_btn" value="Search">
                         
                                                         </form>
                         
                         
                         
                                                     </div>
                            -->
                            <div class="clear_fix"></div>

                        </div>

                        <table class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>S.No.</th>
                                    <th>Bank Name</th>
                                    <th>Account No.</th>
                                    <th>Transaction Id</th>
                                    <th>Date</th>
                                    <th>Note</th>
                                </tr>

                            </thead>   

                            <tbody>

<?php
$rec_limits = 3;



$condition_search = '';

$value = '';
/*
  if (isset($_POST['search_value'])) {
  $value = trim($_POST['search_value']);
  if (!empty($value)) {
  $cond_where = ' AND';
  $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
  }
  }
  if (isset($_GET['srch_value'])) {
  $value = $_GET['srch_value'];
  if (!empty($value)) {
  $cond_where = ' AND';
  $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
  }
  }
 */


$select_count_detail = "SELECT count(at_id) FROM tbl_aff_transfer WHERE at_affilate_id= '" . $_GET['user_id'] . "'" . $condition_search;

$result_count_detail = mysql_query($select_count_detail);



$row_detail = mysql_fetch_array($result_count_detail);

$rec_count_detail = $row_detail[0];



if (isset($_GET['pages'])) {

    $pages = $_GET['pages'] + 1;

    $offsets = $rec_limits * $pages;
} else {

    $pages = 0;

    $offsets = 0;
}
$serial_numbers = $pages * $rec_limits;
$left_recs = $rec_count - ($pages * $rec_limits);
$select_bank = "SELECT * FROM tbl_aff_transfer WHERE at_affilate_id= '" . $_GET['user_id'] . "'" . $condition_search . " ORDER BY at_id DESC LIMIT " . $offset . ", " . $rec_limit;
$query_bank = mysql_query($select_bank) or die(mysql_error());

$i = 1;

if (mysql_num_rows($query_bank) > 0) {

    while ($rows = mysql_fetch_array($query_bank)) {

        $serial_numbers++;

        echo '
						<tr><td>' . $serial_numbers . '</td>
						<td>' . $rows['bank_name'] . '</td>
						<td>' . $rows['account_number'] . '</td>
        					<td>' . $rows['transaction_id'] . '</td>
						<td>' . $rows['at_date'] . '</td>
                                                <td>' . $rows['at_note'] . '</td>';
        echo '
        						</tr>

										';

        $i++;
    }
} else {

    echo '<tr>

										<td colspan="9" style="text-align:center;">No Records Found</td>

									</tr>';
}
?>						

                            </tbody>

                        </table>  

                                <?php
                                echo '<ul class="pagination">';

                                if ($rec_count > $rec_limit) {

                                    if ($page > 0 && $left_rec > $rec_limit) {

                                        $last = $page - 2;

                                        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li> ';

                                        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                                    } else if ($page == 0) {

                                        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                                    } else if ($left_rec < $rec_limit || $left_rec == $rec_limit) {

                                        $last = $page - 2;

                                        echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li>';
                                    }
                                }

                                echo '</ul>';
                                ?>

                    </div>

                </div>

            </div><!--/col-->



        </div><!--/row-->

<?php include_once('footer.php'); ?>

        <script>

                                                                                    $ = jQuery.noConflict();

                                                                                    $(document).ready(function() {

                                                                                        $("#payment_method").change(function() {
                                                                                            if ($(this).val() == 'bank') {
                                                                                                $("#paypal_details").hide();
                                                                                                $(".bank_details").show();
                                                                                            } else {
                                                                                                $("#paypal_details").show();
                                                                                                $(".bank_details").hide();
                                                                                            }
                                                                                        });


                                                                                        $("#add_bank_detail").click(function() {
                                                                                            var bank_name = $("#bank_name").val();
                                                                                            var account_number = $("#account_number").val();
                                                                                            var transaction_id = $("#transaction_id").val();
                                                                                            var pending_amount = $("#pending_amount").val();
                                                                                            var total_amount = $("#total_amount").val();
                                                                                            var at_date = $("#at_date").val();
                                                                                            //var paypal_name = $("#b_paypal_name").val();
                                                                                            var regex = /(\d.*){10}/;
                                                                                            if (bank_name == '') {
                                                                                                alert('Please enter bank name');
                                                                                                $('#bank_name').focus();
                                                                                                return (false);
                                                                                            } else if (account_number == '') {
                                                                                                alert('Please enter account no');
                                                                                                $('#account_number').focus();
                                                                                                return (false);
                                                                                            } else if (transaction_id == '') {
                                                                                                alert('Please enter transaction id');
                                                                                                $('#withdraw').focus();
                                                                                                return (false);
                                                                                            } else if (pending_amount == '') {
                                                                                                alert('Please enter pending amount');
                                                                                                $('#pending_amount').focus();
                                                                                                return (false);
                                                                                            } else if (total_amount == '') {
                                                                                                alert('Please enter total amount');
                                                                                                $('#total_amount').focus();
                                                                                                return (false);
                                                                                            } else if (at_date == '') {
                                                                                                alert('Please enter date');
                                                                                                $('#at_date').focus();
                                                                                                return (false);
                                                                                            } else {
                                                                                                $("#add_aff_bank_detail").submit();
                                                                                            }

                                                                                        });

                                                                                    });
        </script>

    </div><!-- End Box Div-->

</div><!-- End Middle Content Div-->

<?php include_once('footer.php'); ?>

<script type="text/javascript" src="inner_js/bootstrap-datepicker.min.js"></script>

<script>

    $ = jQuery.noConflict();

    $(document).ready(function() {

        $('.chk_sub_chkbox').live('click', function() {

            var payer_id = $(this).next().next('input#userdtlpayerId').val();

            if ($('#sel_pay_type' + payer_id + ':checked').length != 0) {

                if ($('#pay_type_status' + payer_id).val() == '') {

                    alert('Plaese Select One payment Method');

                    $('#sel_pay_type' + payer_id + '').trigger('click');

                }

                else {

                    var user_dtl_pyr_id = payer_id;

                    var status_pay_type = $('#pay_type_status' + user_dtl_pyr_id).val();

                    $.ajax({
                        type: 'POST',
                        data: {pay_type_status: status_pay_type, userdtlpayerId: user_dtl_pyr_id},
                        dataType: 'json',
                        url: '../classess/user_paid_type.php',
                        success:
                                function(j)

                                {

                                    console.log(j);

                                    $('form#paidStatusForm' + user_dtl_pyr_id).parent('td').html(j);

                                }

                    });

                }

            }

        });



        $('.close').click(function() {

            $('.alert-info').addClass('hide');

        });



        $('#count_val').keyup(function() {

            var val = $('#count_val').val();

            var j_user_id = $('#user_id_val').val();

            var j_user_dtl_id = $('#user_dtl_id_val').val();

            if (val > 0) {

                $.ajax({
                    type: 'POST',
                    data: {field_value: val, pst_user_id: j_user_id, pst_user_dtl_id: j_user_dtl_id},
                    dataType: 'json',
                    url: '../classess/ebook_download_time.php',
                    success:
                            function(j)

                            {

                                $('#count_val').val(val);

                            }

                });

            }

        });

        $('.date-picker').datepicker();


        $('#from_date').datepicker({
            format: 'yyyy-mm-dd'
        }).on('changeDate', function(e) {
            $(this).datepicker('hide');
        });

        $('#to_date').datepicker({
            format: 'yyyy-mm-dd'
        }).on('changeDate', function(e) {
            $(this).datepicker('hide');
        });

    });





</script>